﻿using UnityEngine;
using System.Collections;

public class SnapAngle{
	private float offset = 10.0f;
	public Vector3 GetSnappedAngle(Vector3 angle){
		float newX, newY, newZ;
		newX = SnapTo(angle.x);
		newY = SnapTo(angle.y);
		newZ = SnapTo(angle.z);
		Vector3 newAngle = new Vector3(newX, newY, newZ);
		return newAngle;
	}
	
	private float SnapTo(float f){
		if(Mathf.Abs(f) < offset)
			f= 0.0f;
		else if(Mathf.Abs(f - 90.0f) < offset)
			f = 90.0f;
		else if(Mathf.Abs(f - 180.0f) < offset)
			f = 180.0f;
		else if(Mathf.Abs(f - 270.0f) < offset)
			f = 270.0f;
		else if(Mathf.Abs(f - 360.0f) < offset)
			f = 360.0f;
		return f;
	}
	
	
}
